//
//  ElecCheckView.swift
//  SBSafetyApp
//
//  Created by Lina on 2023/11/27.
//

import Foundation
import UIKit

class ElecCheckView: UIView {
    let titleL = UILabel()
    let desL = UILabel()

    let submitBtn = UIButton.createPrimaryLarge("确认")
    let cancelBtn = UIButton.createCustom("取消")
    let rejectBtn = UIButton.createCustom("驳回")
    let nextBtn = UIButton.createPrimaryLarge("继续填报")
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func reloadUI(withModal modal: CheckHsModal) {
        if let status = modal.status { // 状态：0 无\可发起审批  1 接收人详情  2 发起人详情
            switch status {
            case "1":
                desL.text = "\(modal.info?.fqrxm ?? "")向您发起"
//                desL.text = "协同人向您发起"
                submitBtn.isHidden = false
                rejectBtn.isHidden = false
                nextBtn.isHidden = true
                cancelBtn.isHidden = true
                break;
            case "2":
                desL.text = "您向\(modal.info?.jsrxm ?? "")发起确认"
//                desL.text = "您向协同人发起"
                submitBtn.isHidden = true
                rejectBtn.isHidden = true
                nextBtn.isHidden = !(modal.info?.status  == "1")
                cancelBtn.isHidden = (modal.info?.status == "2")
                break;
            default:
                break;
            }
        }
        
        if let infoStatus = modal.info?.status { // 0 未处理  1 确认  2 取消
            switch infoStatus {
            case "0":
                titleL.text = "\(modal.info?.tzlxmc ?? "")待确认"
                break;
            case "1":
                titleL.text = "\(modal.info?.tzlxmc ?? "")已确认"
                break;
            case "3":
                titleL.text = "\(modal.info?.tzlxmc ?? "")已驳回"
                break;
            default:
                titleL.text = ""
                break;
            }
        }
    }
    
    func setupUI() {
        
        let bottomIV = UIImageView(image: UIImage(named: "elec_bottom"))
        addSubview(bottomIV)
        bottomIV.snp.makeConstraints { (make) -> Void in
            make.centerX.equalToSuperview()
//            make.top.equalTo(submitBtn.snp.bottom).offset(20)
            make.bottom.equalTo(self.safeAreaLayoutGuide.snp.bottom).offset(-16)
            make.height.equalTo(24)
        }
        
        let baseV = UIView()
        baseV.backgroundColor = .white
        baseV.layer.cornerRadius = 10
        baseV.layer.masksToBounds = true
        baseV.layer.shadowOffset = CGSize(width: 0, height: 6)
        baseV.layer.shadowOpacity = 0.08
        baseV.layer.shadowColor = UIColor.black.cgColor
        addSubview(baseV)
        baseV.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(self.snp.top).offset(10)
            make.centerX.equalTo(self.snp.centerX)
            make.width.equalTo(ScreenWidth - 20)
            make.bottom.equalTo(bottomIV.snp.top).offset(-26)
        }
        
        let iconIV = UIImageView(image: UIImage(named: "elec_icon"))
        iconIV.sizeToFit()
        baseV.addSubview(iconIV)
        iconIV.snp.makeConstraints { (make) -> Void in
            make.centerX.equalToSuperview()
            make.top.equalToSuperview().offset(90)
            make.width.height.equalTo(90)
        }
        
        titleL.font = UIFont.systemFont(ofSize: 25)
        titleL.textColor = .hex("#262626")
        baseV.addSubview(titleL)
        titleL.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(iconIV.snp.bottom).offset(40)
            make.centerX.equalToSuperview()
        }
        
        desL.font = UIFont.systemFont(ofSize: 17)
        desL.textColor = .hex("#CCCCCC")
        desL.textAlignment = .center
        baseV.addSubview(desL)
        desL.snp.makeConstraints { (make) -> Void in
            make.top.equalTo(titleL.snp.bottom).offset(20)
            make.left.equalToSuperview().offset(20)
            make.right.equalToSuperview().offset(-20)
            make.centerX.equalToSuperview()
        }
        
        cancelBtn.isHidden = true
        baseV.addSubview(cancelBtn)
        cancelBtn.snp.makeConstraints { (make) -> Void in
            make.bottom.equalToSuperview().offset(-40)
            make.height.equalTo(50)
            make.centerX.equalToSuperview()
            make.width.equalTo(220)
        }
        
        submitBtn.isHidden = true
        baseV.addSubview(submitBtn)
        submitBtn.snp.makeConstraints { (make) -> Void in
            make.bottom.equalTo(cancelBtn.snp.top)
            make.height.equalTo(50)
            make.centerX.equalToSuperview()
            make.width.equalTo(220)
        }
        
        rejectBtn.isHidden = true
        baseV.addSubview(rejectBtn)
        rejectBtn.snp.makeConstraints { (make) -> Void in
            make.bottom.equalToSuperview().offset(-40)
            make.height.equalTo(50)
            make.centerX.equalToSuperview()
            make.width.equalTo(220)
        }
        
        nextBtn.isHidden = true
        baseV.addSubview(nextBtn)
        nextBtn.snp.makeConstraints { (make) -> Void in
            make.bottom.equalTo(cancelBtn.snp.top)
            make.height.equalTo(50)
            make.centerX.equalToSuperview()
            make.width.equalTo(220)
        }
    }
}
